/**
 * 
 */
package edu.umd.clip.lm.storage.remote;

import java.nio.ByteBuffer;

import edu.umd.clip.lm.storage.remote.Message.MessageHeader;


/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public class PingMessage extends Message {
	int length;
	/**
	 * @param length
	 */
	public PingMessage(int length) {
		super(MessageHeader.PING_MESSAGE, 0);
		this.length = length; 
	}

	public PingMessage(int replyTo, int length) {
		this(length);
		setReplyTo(replyTo); 
	}

	public PingMessage() {
		this(0);
	}

	public PingMessage(MessageHeader header, ByteBuffer buffer) {
		super(header);
		readBody(buffer);
	}
	

	/* (non-Javadoc)
	 * @see edu.umd.clip.lm.storage.remote.Message#readBody(java.nio.ByteBuffer)
	 */
	@Override
	protected void readBody(ByteBuffer buffer) {
		length = buffer.getInt();
		byte bytes[] = new byte[length];
		buffer.get(bytes);
	}

	/* (non-Javadoc)
	 * @see edu.umd.clip.lm.storage.remote.Message#writeBody()
	 */
	@Override
	protected ByteBuffer writeBody() {
		ByteBuffer buffer = ByteBuffer.allocate(length + 4);
		buffer.putInt(length);
		byte bytes[] = new byte[length];
		buffer.put(bytes);
		return buffer;
	}

}
